﻿namespace Sidvall.Resources
{
    public abstract class ResourceProviderBase : IResourceProvider
    {
        #region Public Members

        protected abstract System.Resources.ResourceManager GetResourceManager(string group, string key);

        #region GetString

        public string GetString(string group, string key)
        {
            Sidvall.SystemContext.Current.CultureManager.EnsureCorrectCurrentUICulture();
            if (string.IsNullOrWhiteSpace(key))
                return string.Empty;
            var value = GetResourceManager(group, key).GetString(key);
            if (string.IsNullOrWhiteSpace(value))
                return key;
            return value;
        }
        public string GetString(string group, string key, System.Globalization.CultureInfo culture)
        {
            Sidvall.SystemContext.Current.CultureManager.EnsureCorrectCurrentUICulture();
            if (string.IsNullOrWhiteSpace(key))
                return string.Empty;
            var value = GetResourceManager(group, key).GetString(key, culture);
            if (string.IsNullOrWhiteSpace(value))
                return key;
            return value;
        }

        #endregion

        #region ToString

        public override string ToString()
        {
            return "ResourceProviderBase - Sidvall";
        }

        #endregion

        #endregion
    }
}
